import { View } from "../../../../mvc/core/View";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { ClickToShowItemTip } from "../../common/tooltip/ClickToShowItemTip";
import { MsgManager } from "../../../manager/MsgManager";
import { TodayNotTipUtil } from "../../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../../component/gconst/TodayNoTipsConst";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Cache } from "../../../cache/Cache";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { EProp } from "../../../../../Message/Public/EProp";
import { MountUtil } from "../../../scene/mount/MountUtil";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MountEquipAttInfo } from "./MountEquipAttInfo";
import { MountConfig } from "../../../resource/MountConfig";
import { EColor } from "../../../../../Message/Public/EColor";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemConfig } from "../../../resource/ItemConfig";
import { EquipmentItemDataUtil } from "../../common/EquipmentItemDataUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { TMountEquipUpgrade } from "../../../../../Message/Db/Tables/TMountEquipUpgrade";
import { _isCur } from "../../../../../this/_isCur";
type int = number;
//class MountEquipAttSp
    
    export  class MountEquipAttSp extends View
    {
        constructor(arg1: Boolean=true)
        {
            super();
            this._attArr = [];
            this._isCur = arg1;
            this.initView();
            return;
        }

        public get attArr(): Array<any>
        {
            return this._attArr;
        }

        /* internal  */initView(): void
        {
            ObjCreate.createBg(0, 0, 170, 130, this);
            this._stBm = ObjCreate.createBitmap("", 17, 6, this);
            this._stFightBm = ObjCreate.createBitmap("", 3, 107, this);
            this._startLvTx = ObjCreate.createGTextField("_startLvTx", 95, 5, 60, 20, this, GlobalStyle._textFormat6);
            this._attTx = ObjCreate.createGTextField("_attTx", 24, 30, 143, 75, this, GlobalStyle._textFormat6);
            this._attTx.wordWrap = true;
            this._attTx.multiline = true;
            this._fightTx = ObjCreate.createGTextField("_fightTx", 79, 106, 67, 20, this, GlobalStyle._textFormat6);
            var loc1=0;
            while (loc1 < 4) 
            {
                ObjCreate.createBg(0, 24 + 25 * loc1, 200, 2, this, ImagesConst.Line);
                ++loc1;
            }
            this._riseBm = ObjCreate.createBitmap(ImagesConst.RangeRaise, 128, 104, this);
            this._costTx = ObjCreate.createGTextField("_costTx", 47, 187, 124, 20, this, GlobalStyle.textFormat5);
            this._costTx.addEventListener(flash.events.TextEvent.LINK, this.onResetModleTxClick);
            this._btn = ObjCreate.createGButton("_btn", 40, 138, 83, 25, this, "ButtonRedMini");
            this._btn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClick);
            if (this._isCur) 
            {
                this._btn.label = Language.getString(74216);
            }
            else 
            {
                this._btn.label = Language.getString(74217);
            }
            this._costYBSp = new Object /* flash.display.Sprite */();
            this._costYBSp.x = 20;
            this._costYBSp.y = 167;
            addChild(this._costYBSp);
            ObjCreate.createBg(0, 0, 120, 19, this._costYBSp, ImagesConst.FightingStrgBg);
            var loc2=ObjCreate.createGTextField(Language.getString(26225), 3, 0, 55, 20, this._costYBSp, GlobalStyle.textFormat6);
            this._costYBtx = ObjCreate.createGTextField("ssssss", 65, 0, 40, 20, this._costYBSp, GlobalStyle._textFormat2);
            ObjCreate.createBitmap(ImagesConst.Yuanbao, 94, 2, this._costYBSp);
            var loc3=ObjCreate.createGTextField(Language.getString(79012), 12, 187, 35, 20, this);
            this.showNext();
            LoaderHelp.addResCallBack(ResFileConst.mountEquip, this.onLoadBmResource);
            return;
        }

        protected onResetModleTxClick(arg1: Object /* flash.events.TextEvent */): void
        {
            ClickToShowItemTip.instance.setItemCodeAndShow(this._costItemCode);
            return;
        }

        protected onBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._info || !this._info.curData) 
            {
                MsgManager.showRollTipsMsg(Language.getString(79009));
                return;
            }
            if (this.isOrangeMaxLv) 
            {
                MsgManager.showRollTipsMsg(Language.getString(71558));
                return;
            }
            if (!this.canUpgrade) 
            {
                MsgManager.showRollTipsMsg(Language.getString(74215));
                return;
            }
            if (!this.enoughCost) 
            {
                MsgManager.showRollTipsMsg(Language.getString(70316));
                return;
            }
            if (!this.enoughMatiriel) 
            {
                MsgManager.showRollTipsMsg(Language.getString(71109));
                return;
            }
            if (this._isCur) 
            {
                this.goUpgrade();
            }
            else 
            {
                TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.MountEquipGoUpgradeCost, this.goUpgrade, Language.getStringByParam(79013, this._tcostinfo.cost), null, Alert.OK | Alert.CANCEL, null, null, null, 4);
            }
            return;
        }

        /* internal  */goUpgrade(): void
        {
            var loc1=null;
            var loc2=null;
            if (this._tcostinfo) 
            {
                loc1 = Cache.instance.pack.backPackCache.getTypeItemsByColor(ECategory._ECategoryProp, EProp._EPropMountEquipAdvance, this._tcostinfo.materialColor, true);
                loc2 = MountUtil.instance.getAllUid(loc1);
                Dispatcher.dispatchEvent(new DataEvent(EventName.MountEquipGoUpgrade, {"posType": this._info.curData.posType, "equipUid": this._info.curData.uid, "materials": loc2, "isCur": _isCur}));
            }
            return;
        }

        public updateInfo(arg1: MountEquipAttInfo): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            this._info = arg1;
            this.canUpgrade = false;
            this._tcostinfo = null;
            this.isOrangeMaxLv = false;
            if (this._info && this._info.curData) 
            {
                if (this._info.curData && !MountConfig.instance.isMountEquipFullStat(this._info.curData.type, this._info.curData.color, this._info.curData.itemExInfo.m_equip_star)) 
                {
                    loc2 = [];
                    loc3 = new Map<any, any> /* flash.utils.Dictionary */();
                    if (Cache.instance.role.mountMaxReinValue < 4) 
                    {
                        if (this._info.curData.color >= EColor._EColorOrange && this._info.curData.itemExInfo.m_equip_star >= MountConfig.instance.getMountEquipStarByTypeColor(this._info.curData.type, this._info.curData.color)) 
                        {
                            this.isOrangeMaxLv = true;
                        }
                    }
                    if (this._info.curData.itemExInfo.m_equip_star + 1 > MountConfig.instance.getMountEquipStarByTypeColor(this._info.curData.type, this._info.curData.color)) 
                    {
                        if ((loc5 = new ItemData(ItemConfig.instance.getPropByCateTypeColor(this._info.curData.category, this._info.curData.type, this._info.curData.color + 1).item.code)) && !(loc5 == ItemData.nullItemData)) 
                        {
                            loc2 = (loc4 = new EquipmentItemDataUtil(loc5)).getBasePropArray();
                            loc3 = MountUtil.instance.getMountEquipAddAttDict(loc5.type, loc5.color, 0);
                            this._tcostinfo = MountConfig.instance.getMountEquipUpgradeInfo(loc5.type, loc5.color, 0);
                            this.canUpgrade = true;
                        }
                        else 
                        {
                            this.canUpgrade = false;
                        }
                    }
                    else 
                    {
                        loc2 = (loc4 = new EquipmentItemDataUtil(arg1.curData)).getBasePropArray();
                        loc3 = MountUtil.instance.getMountEquipAddAttDict(this._info.curData.type, this._info.curData.color, this._info.curData.itemExInfo.m_equip_star + 1);
                        this._tcostinfo = MountConfig.instance.getMountEquipUpgradeInfo(this._info.curData.type, this._info.curData.color, this._info.curData.itemExInfo.m_equip_star + 1);
                        this.canUpgrade = true;
                    }
                }
                else 
                {
                    this.canUpgrade = false;
                }
                if (this._isCur) 
                {
                    this._fightTx.htmlText = "<font color=\'#f0ea3f\'>" + Cache.instance.role.combatCapabilities + "</font>";
                    loc2 = (loc4 = new EquipmentItemDataUtil(arg1.curData)).getBasePropArray();
                    loc3 = MountUtil.instance.getMountEquipAddAttDict(arg1.curData.type, arg1.curData.color, arg1.curData.itemExInfo.m_equip_star);
                }
                else 
                {
                    this._fightTx.text = "";
                }
                this._attTx.htmlText = this.getAttTx(loc2, loc3);
                this._startLvTx.text = arg1.starLv + " " + Language.getString(60288);
                this.showNext();
                this.updateMaterial();
            }
            else 
            {
                this.clean();
            }
            return;
        }

        /* internal  */getAttTx(arg1: Array<any>, arg2: Map<any, any> /* flash.utils.Dictionary */): string
        {
            var loc3=0;
            var loc5=0;
            var loc6=null;
            var loc7=null;
            this._attArr = [];
            var loc1="";
            var loc2="";
            var loc4="";
            var loc8=0;
            while (loc8 < arg1.length) 
            {
                loc7 = arg1[loc8] as Map<any, any> /* flash.utils.Dictionary */;
                loc6 = new Map<any, any> /* flash.utils.Dictionary */();
                loc3 = loc7["value"];
                loc4 = "";
                loc5 = loc7["type"];
                loc2 = loc7["name"];
                loc6["type"] = loc5;
                if (arg2[loc5.toString()]) 
                {
                    loc4 = "  +  " + arg2[loc5.toString()];
                    loc6["value"] = loc3 + arg2[loc5.toString()];
                }
                else 
                {
                    loc4 = "  +  0";
                    loc6["value"] = loc3;
                }
                this._attArr.push(loc6);
                loc1 = loc1 + (loc2 + "  " + loc3 + loc4 + "\r");
                ++loc8;
            }
            return "<textFormat leading=\'12\'><font color=\'#ffffff\'>" + loc1 + "</textFormat></font>";
        }

        public updateMaterial(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            if (this._info && this._info.curData && this.canUpgrade && this._tcostinfo) 
            {
                this.enoughCost = false;
                this.enoughMatiriel = false;
                this._costItemCode = ItemConfig.instance.getPropByCateTypeColor(ECategory._ECategoryProp, EProp._EPropMountEquipAdvance, this._tcostinfo.materialColor).item.code;
                loc1 = new ItemData(this._costItemCode);
                if (loc1 && !(loc1 == ItemData.nullItemData)) 
                {
                    loc3 = ColorConfig.instance.getItemColorString(loc1.color);
                    loc4 = "";
                    loc2 = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropMountEquipAdvance, -1, this._tcostinfo.materialColor);
                    if (this._isCur) 
                    {
                        loc4 = HTMLUtil.addColor("*" + this._tcostinfo.materialAmount, loc3);
                        if (loc2 < this._tcostinfo.materialAmount) 
                        {
                            this.enoughMatiriel = false;
                        }
                        else 
                        {
                            this.enoughMatiriel = true;
                        }
                        this.enoughCost = true;
                    }
                    else 
                    {
                        if (Cache.instance.role.money.gold < this._tcostinfo.cost) 
                        {
                            this.enoughCost = false;
                        }
                        else 
                        {
                            this.enoughCost = true;
                        }
                        this._costYBtx.text = this._tcostinfo.cost.toString();
                        if (loc2 < Math.ceil(this._tcostinfo.materialAmount / 2)) 
                        {
                            this.enoughMatiriel = false;
                        }
                        else 
                        {
                            this.enoughMatiriel = true;
                        }
                        loc4 = HTMLUtil.addColor(" * " + Math.ceil(this._tcostinfo.materialAmount / 2), loc3);
                    }
                    this._costTx.htmlText = Language.getStringByParam(74218, ItemsUtil.getItemName(loc1) + loc4);
                }
            }
            else 
            {
                this.clean();
            }
            return;
        }

        public updateAddFightTx(arg1: int, arg2: Boolean): void
        {
            if (arg2) 
            {
                this._fightTx.htmlText = "<font color=\'#f0ea3f\'>" + arg1 + "</font>";
            }
            else 
            {
                this._fightTx.htmlText = "<font color=\'#60e71e\'>" + arg1 + "</font>";
            }
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            if (this._isCur) 
            {
                this._stBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.mountEquip_CurStar);
                this._stFightBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.curFightValue);
            }
            else 
            {
                this._stBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.mountEquip_nextStar);
                this._stFightBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.riseFightValue);
            }
            return;
        }

        /* internal  */showNext(): void
        {
            if (this._isCur) 
            {
                this._costYBSp.visible = false;
                this._riseBm.visible = false;
            }
            else 
            {
                this._costYBSp.visible = true;
                this._riseBm.visible = true;
            }
            return;
        }

        public clean(): void
        {
            this._startLvTx.text = "";
            this._attTx.text = "";
            this._fightTx.text = "";
            this._costTx.text = "";
            this._costYBSp.visible = false;
            this.enoughCost = false;
            this.enoughMatiriel = false;
            this.canUpgrade = false;
            this._tcostinfo = null;
            this._costItemCode = 0;
            this._info = null;
            this.isOrangeMaxLv = false;
            return;
        }

        /* internal */ /* var */_stBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_stFightBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_startLvTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_attTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_fightTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_btn: GButton;

        /* internal */ /* var */_costTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_costYBtx: Object /* flash.text.TextField */;

        /* internal */ /* var */_costYBSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_isCur: Boolean;

        /* internal */ /* var */_riseBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_info: MountEquipAttInfo;

        /* internal */ /* var */canUpgrade: Boolean;

        /* internal */ /* var */enoughCost: Boolean;

        /* internal */ /* var */enoughMatiriel: Boolean;

        /* internal */ /* var */_tcostinfo: TMountEquipUpgrade;

        /* internal */ /* var */_costItemCode: int;

        /* internal */ /* var */isOrangeMaxLv: Boolean;

        /* internal */ /* var */_attArr: Array<any>;
    }
